﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace LimpaGaragem.DAO.Product
{
    public class TransactionType
    {
        /// <summary>
        /// Return list of status
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.Product.TransactionType> GetListOfTransactionType()
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR011_ListProductTransactionTypes", 0);

                List<LimpaGaragem.Model.Product.TransactionType> objListOfTransactionType = new List<LimpaGaragem.Model.Product.TransactionType>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.Product.TransactionType objTransactionType = new LimpaGaragem.Model.Product.TransactionType();
                    objTransactionType.ID = Convert.ToInt32(objDataRow["ID_TRANSACTION_TYPE"]);
                    objTransactionType.Name = objDataRow["NM_TRANSACTION_TYPE"].ToString();
                    objListOfTransactionType.Add(objTransactionType);
                }
                return objListOfTransactionType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Return data of status
        /// </summary>
        /// <returns></returns>
        public LimpaGaragem.Model.Product.TransactionType GetTransactionType(int IDTransactionType)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_TRANSACTION_TYPE", IDTransactionType));

                //RETURN DATA
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR011_SelectProductTransactionType", 0, objListOfParameters);

                LimpaGaragem.Model.Product.TransactionType objTransactionType = null;
                if (objDataTable.Rows.Count > 0)
                {
                    objTransactionType = new LimpaGaragem.Model.Product.TransactionType();
                    objTransactionType.ID = IDTransactionType;
                    objTransactionType.Name = objDataTable.Rows[0]["NM_TRANSACTION_TYPE"].ToString();
                }
                return objTransactionType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
